
<!-- 评论 -->
<template>
	<view class="item flex">
		<view class="usertop">
			<image :src="it.avatar" mode=""></image>
		</view>
		<view class="right">
			<view class="user flex justify-between align-center">
				<view class="username">
					<view class="text flex align-center">
						<text>{{it.userName}}</text>
						<!-- <view class="vip">
							<image :src="it.vipimg" mode=""></image>
						</view> -->
					</view>
					<view class="signature" v-if="it.company && it.position">
						{{it.company}}·{{it.position}}
					</view>
				</view>
				<view class="thumbup flex justify-center align-center">
					<text :class="shaw?'active':''">{{num}}</text>
					<view class="zang flex justify-center align-center">
						<image v-if="!shaw" src="https://sanfuzhide.oss-cn-hangzhou.aliyuncs.com/circle/zan.png"
							mode="" @click="dianzan"></image>
						<image v-if="shaw"
							src="https://sanfuzhide.oss-cn-hangzhou.aliyuncs.com/circle/zan-active.png" mode="" @click="dianzan"></image>
					</view>
				</view>
			</view>
			<view class="content flex align-center">
				{{it.content}}
			</view>
			<view class="btm flex align-center">
				<view class="date">
					{{getTimer(it.createDate)}}
				</view>
				<view class="link" @click="huifu(it)">
					回复
				</view>
			</view>
			<view class="reply" v-if="it.getArticleCommentReplies.length != 0">
				<view v-if="!show" class="top flex align-center">
					<view class="imgs">
						<image :src="it.getArticleCommentReplies[0].avatar" mode=""></image>
					</view>
					<view class="name">
						{{it.getArticleCommentReplies[0].userName}}
					</view>
					<view v-if="it.getArticleCommentReplies[0].type" class="author flex justify-center align-center">
						作者
					</view>
					<view class="cont">
						: {{it.getArticleCommentReplies[0].content}}
					</view>
				</view>
				<view v-if="show" class="top flex align-center" v-for="(items,index) in it.getArticleCommentReplies" :key="index">
					<view class="imgs">
						<image :src="items.avatar" mode=""></image>
					</view>
					<view class="name">
						{{items.userName}}
					</view>
					<view v-if="items.type" class="author flex justify-center align-center">
						作者
					</view>
					<view class="cont">
						: {{items.content}}
					</view>
				</view>
				<view v-if="it.getArticleCommentReplies.length > 1 && !show" class="an" @click="likean">
					查看更多{{it.getArticleCommentReplies.length - 1}}条回复
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "articleComments",
		props: {
			it: Object
		},
		data() {
			return {
				show: false,
				shaw: this.it.likeType,
				num: this.it.likeNum,
				qurey:{
					articleCommentId: this.it.articleCommentId
				}
			}
		},
		methods: {
			huifu(e){
				console.log(e)
				uni.setStorageSync('pageNum',e.articleCommentId)
				this.$emit("changeshowe",true)
			},
			getTimer(timer) {
			  
			  let nowe = new Date();  // 当前的系统时间
			  let oldtime = new Date(timer);   //目标时间
			  let t_day = oldtime.getDate();
			  let t_year = oldtime.getFullYear();
			  let t_month = oldtime.getMonth() + 1;
			  let t_hour = oldtime.getHours();
			  let t_minute = oldtime.getMinutes();
			  if (t_hour<10){
			    t_hour = '0' + t_hour
			  }
			  if (t_minute < 10) {
			    t_minute = '0' + t_minute
			  }
			  let n_year = nowe.getFullYear();
			  let n_month = nowe.getMonth() + 1;
			  let n_day = nowe.getDate();
			  let mistiming = nowe - oldtime; // 计算出当前时间，与目标时间的时间差
			  if (t_year == n_year) {
			    if (n_month == t_month) {
			      //  在同一月  
			      if (n_day - t_day == 1) {
			        // 差等于1 昨天 + 时分
					console.log('昨天' + ' ' + t_hour + ':' + t_minute)
			        return '昨天' + ' ' + t_hour + ':' + t_minute
			      } else if (n_day - t_day == 0) {
			        // 显示 时分
					console.log( t_hour + ':' + t_minute)
			        return t_hour + ':' + t_minute
			      } else {
					console.log(t_month + '.' + t_day + ' ' +t_hour + ':' + t_minute)
			        return t_month + '.' + t_day + ' ' +t_hour + ':' + t_minute
			      }
			    }else {
					console.log(t_month + '.' + t_day)
					return t_month + '.' + t_day + ' ' +t_hour + ':' + t_minute
				}
			  } else {
			    //跨年了  显示 年 月 日 
				console.log(t_year + '.' + t_month + '.' + t_day + ' ' +t_hour + ':' + t_minute)
			    return t_year + '.' + t_month + '.' + t_day + ' ' +t_hour + ':' + t_minute
			  }
			},
			//点击展示更多
			likean() {
				this.show = true
			},
			//评论点赞
			async dianzan() {
				if(uni.getStorageSync('openId')){
					let{code} = await this.$post('/articleList/likeArticleComment',this.qurey)
				if(code == 200){
					this.shaw = !this.shaw
					if(this.shaw){
						this.num += 1
					}else{
						this.num -= 1
					}
				}
				}else{
					uni.navigateTo({
						url:'../../pages/login/login'
					})
				}
				
			},
			onLoad() {
				// console.log(it)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.item {
		padding-top: 30rpx;

		.usertop {
			width: 72rpx;
			height: 72rpx;
			margin-right: 16rpx;
		}

		.right {
			width: 602rpx;
			border-bottom: 1rpx solid #f5f5f5;
			padding-bottom: 30rpx;

			.user {
				.username {
					.text {
						text {
							font-weight: bold;
							color: #333333;
							font-size: 28rpx;
							margin-right: 10rpx;
						}

						.vip {
							width: 40rpx;
							height: 40rpx;
						}
					}

					.signature {
						font-weight: 500;
						color: #999999;
						font-size: 24rpx;
					}
				}

				.thumbup {
					text {
						font-weight: 500;
						color: #333333;
						font-size: 28rpx;
						margin-right: 10rpx;
					}

					.active {
						color: #0265EB;
					}

					.zang {
						width: 26rpx;
						height: 26rpx;
					}
				}
			}

			.content {
				font-weight: 500;
				color: #333333;
				font-size: 28rpx;
				margin: 20rpx 0;
			}

			.btm {
				font-weight: 500;
				color: #999999;
				font-size: 24rpx;

				.date {
					margin-right: 30rpx;
				}
			}

			.reply {
				width: 100%;
				background: #F1F1F1;
				border-radius: 8px;
				padding: 20rpx;
				margin-top: 10rpx;

				.top {
					margin-top: 10rpx;

					.imgs {
						width: 40rpx;
						height: 40rpx;
						margin-right: 10rpx;
					}

					.name {
						font-weight: 500;
						color: #333333;
						font-size: 24rpx;
						margin-right: 10rpx;
						line-height: 1;
					}

					.author {
						margin-right: 10rpx;
						padding: 2rpx 5rpx;
						border: 2rpx solid #0265EB;
						border-radius: 5rpx;
						font-weight: 500;
						color: #0265EB;
						font-size: 20rpx;
						line-height: 1;
					}

					.cont {
						font-weight: 500;
						color: #333333;
						font-size: 24rpx;
						line-height: 1;
					}
				}

				&>.top:first-child {
					margin-top: 0;
				}

				.an {
					margin-top: 20rpx;
					font-weight: 500;
					color: #0265EB;
					font-size: 20rpx;
				}
			}
		}
	}
</style>
